package com.fanbuchi.app.ins.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bugtags.library.Bugtags;
import com.fanbuchi.app.ins.R;
import com.fanbuchi.app.ins.adapter.RecyclerAdapter;
import com.fanbuchi.app.ins.event.OnClickEvent;
import com.fanbuchi.app.ins.services.DaemonService;
import com.fanbuchi.app.ins.services.LongSocket;
import com.fanbuchi.app.ins.services.LongSocketService;
import com.fanbuchi.app.ins.vo.HotPoint;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;
//import hiapk.java.com.fanbuchi.app.hiapk.Hiapk;


/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class FullscreenActivity extends AppCompatActivity {

    List<HotPoint> pictures = new ArrayList<>();
    private RecyclerView  fullscreen_content_group;
    RecyclerAdapter mRecyclerAdapter;


    /**
     * @title 默认的 RecyclerView 配置
     * @param mActivity
     * @param container
     * @param adapter
     */
    protected void initRecyclerView(Activity mActivity,RecyclerView container,RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {

        //config
        LinearLayoutManager manager = new LinearLayoutManager(mActivity);
        manager.setOrientation(LinearLayout.HORIZONTAL);//默认是LinearLayout.VERTICAL

        manager.scrollToPosition(0);//用于记录上次位置

        container.setLayoutManager(manager);
        container.setItemAnimator(new DefaultItemAnimator());
        container.setHasFixedSize(true);
        // divider item
//        DividerItemDecoration itemDecoration =
//                new DividerItemDecoration(mActivity,
//                        DividerItemDecoration.VERTICAL_LIST);
//        container.addItemDecoration(itemDecoration);
//        container.setItemAnimator(new SlideInLeftAnimator());
        container.setAdapter(adapter);
    }
    TextView textView;
    ProgressDialog progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_fullscreen);
        EventBus.getDefault().register(this);

        startService(new Intent(this, DaemonService.class));
        //startService(new Intent(this, LongSocketService.class));

        fullscreen_content_group = (RecyclerView)findViewById(R.id.fullscreen_content_group);


        if (mRecyclerAdapter==null){
            HotPoint picture3 = new HotPoint(); picture3.links="http://img3.3lian.com/2013/s1/59/d/73.jpg";
            HotPoint picture1 = new HotPoint(); picture1.links="http://h.hiphotos.baidu.com/image/pic/item/0b55b319ebc4b745b4458323cafc1e178a821535.jpg";
            HotPoint picture2 = new HotPoint(); picture2.links="http://a.hiphotos.baidu.com/image/pic/item/38dbb6fd5266d016091d702c952bd40735fa35a9.jpg";
            pictures.add(picture3);
            pictures.add(picture1);
            pictures.add(picture2);
            mRecyclerAdapter= new RecyclerAdapter(pictures);//welcome page
            initRecyclerView(this, fullscreen_content_group, mRecyclerAdapter);
        }
        fullscreen_content_group.setAdapter(mRecyclerAdapter);

        textView=(TextView)findViewById(R.id.textView);
        //textView.setText( Hiapk.getInstance());
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    //订阅一个校验的对象 就进行数据校验


            }
        });

    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
    }

    @Override
    protected void onRestart() {
        super.onRestart();

    }

    @Override
    protected void onResume() {
        super.onResume();
        Bugtags.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //注：回调 2
        Bugtags.onPause(this);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        //注：回调 3
        Bugtags.onDispatchTouchEvent(this, event);
        return super.dispatchTouchEvent(event);
    }









    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    public void onEvent(OnClickEvent event) {

        mRecyclerAdapter.notifyDataSetChanged();
    }
}
